Quiz: Language Fundamentals

To View Tricks: Login Required

Number of Questions: 13

Question: 1 -

Which is a valid keyword in java?

Options:
  1. Float

  2. unsigned

  3. interface

  4. string

  5. Answer:

    interface

    Solution not available.

Question: 2 -

Which one of these lists contains only Java programming language keywords?

Options:
  1. try, virtual, throw, final, volatile, transient

  2. goto, instanceof, native, finally, default, throws

  3. class, if, void, long, Int, continue

  4. byte, break, assert, switch, include

  5. Answer:

    goto, instanceof, native, finally, default, throws

    Solution:

    All the words in option "goto, instanceof, native, finally, default, throws" are among the 49 Java keywords. Although goto reserved as a keyword in Java, goto is not used and has no function.

    Option "class, if, void, long, Int, continue" is wrong because the keyword for the primitive int starts with a lowercase i.

    Option "try, virtual, throw, final, volatile, transient" is wrong because "virtual" is a keyword in C++, but not Java.

    Option "byte, break, assert, switch, include" is wrong because "include" is a keyword in C, but not in Java.


Question: 3 -

Which four options describe the correct default values for array elements of the types indicated?

  1. int -> 0
  2. String -> "null"
  3. Dog -> null
  4. char -> '\u0000'
  5. float -> 0.0f
  6. boolean -> true

Options:
  1. 1, 2, 3, 4

  2. 1, 3, 4, 5

  3. 2, 4, 5, 6

  4. 3, 4, 5, 6

  5. Answer:

    1, 3, 4, 5

    Solution:

    (1), (3), (4), (5) are the correct statements.

    (2) is wrong because the default value for a String (and any other object reference) is null, with no quotes.

    (6) is wrong because the default value for boolean elements is false.


Question: 4 -

Which is a reserved word in the Java programming language?

Options:
  1. native

  2. array

  3. subclasses

  4. method

  5. Answer:

    native

    Solution:

    The word "native" is a valid keyword, used to modify a method declaration.


Question: 5 -

Which will legally declare, construct, and initialize an array?

Options:
  1. int myList [] = {4, 3, 7};

  2. int [] myList = (5, 8, 2)

  3. int myList [] [] = {4,9,7,0};

  4. int [] myList = {"1", "2", "3"};

  5. Answer:

    int myList [] = {4, 3, 7};

    Solution not available.